// src/logics/useLazyLoad.ts
type apiFunction = () => Promise<void>;
//监听元素是否进入可视区如果进入发送请求获取数据
export default function useLazyLoad(apiFunction: apiFunction) {
  
  const target = ref<HTMLElement>();
  //监听元素是否进入可视区
  const { stop } = useIntersectionObserver(target, ([{ isIntersecting }]) => {
    if (isIntersecting) {
      //停止监听
      stop();
      apiFunction();
    }
  },
  { threshold: 0 }
  );
  //将target返回方法的调用者负责绑定元素，他绑定谁我们就监听谁
  return target;
}